//初始化
var form;
var $;
var element;
layui.use(['element','form'],function(){
    form = layui.form;
    $ = layui.jquery;
    element = layui.element;
    setNums();
    load();
    getEchartsUserInfo();
    window.setInterval(getEchartsUserInfo,300000);
    window.setInterval(setNums,300000);
});
function load(){
    $(".tit_btn").bind('click',function(){
        location.reload();
    });
}
function setNums(){
    $.get("/personnel/selLoginNums", function (res) {
        $(".backNum").html(res.data.backLoginNum);
        $(".beforeNum").html(res.data.beforeLoginNum);
    });
}
function getEchartsUserInfo(){
    $.get("/personnel/getLoginTime", function (res) {
        $.get("/personnel/getLoginTimes", function (data) {
            getEcharts(res.data,data.data);
        });
    });
}
function getEcharts(data,item){
    var chartDom = document.getElementById('userecharts');
    var myChart = echarts.init(chartDom);
    var option;
    option = {
        title: {
            text: '用户登录堆叠区域图'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross',
                label: {
                    backgroundColor: '#6a7985'
                }
            }
        },
        legend: {
            data: ['前端用户登录次数', '管理人员登录次数']
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [
            {
                type: 'category',
                boundaryGap: false,
                data: ['8:00-12:00','12:00-16:00','16:00-20:00','20:00-00:00','00:00-8:00']
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: '前端用户登录次数',
                type: 'line',
                stack: '总量',
                areaStyle: {},
                emphasis: {
                    focus: 'series'
                },
                data: data
            },
            {
                name: '管理人员登录次数',
                type: 'line',
                stack: '总量',
                areaStyle: {},
                emphasis: {
                    focus: 'series'
                },
                data: item
            }
        ]
    };
    option && myChart.setOption(option);
    window.onresize = myChart.resize;
}